import {createRouter,createWebHashHistory} from 'vue-router'
import Login from '../components/Login.vue'
import Index from '../components/Index.vue'
import List from '../components/List.vue'
import Liuyan from '../components/Liuyan.vue'
import Gywm from '../components/Gywm.vue'
import Details from '../components/Details.vue'
const routes = [
	{
		path:'/',
		component:Index,
		children:[
			{
				path:'/',
				component:() => List,
			},
			{
				path:'/Liuyan',
				component:() => Liuyan,
			},
			{
				path:'/Details',
				component:() => Details,
			},
			{
				path:'/Gywm',
				component:() => Gywm,
			}
		]
	},
	{
		path:'/Login',
		name:'Login',
		component:Login
	},
]
const router = createRouter({
	history: createWebHashHistory(),
	routes
})
// 路由守卫
router.beforeEach((to,from,next)=>{
	console.log(to)
	if(to.path=='/'){
		if(localStorage.getItem('USERNAME')){
			next()
		}else{
			next({path:'/Login'})
		}
	}
	next()
})
export default router